/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.batavia.inter.impl;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.util.Cookie;
import java.util.Date;
import java.util.List;
import net.sourceforge.htmlunit.corejs.javascript.ast.CatchClause;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggerFactory;
import org.batavia.domain.Flight;
import org.batavia.inter.InterfaceAirlines;
import org.joda.time.DateTime;

/**
 *
 * @author omenk
 */
public class AirlinesImpl implements InterfaceAirlines {

    LoginImpl login;
    private final Logger logger = Logger.getLogger(AirlinesImpl.class);

    public List<Flight> search(Date departure, String origin, String destination, Integer adult, Integer child, Integer infant) {


        try {
            // inisialisasi HTML Unit
            WebClient client = new WebClient();
            HtmlPage page2 = client.getPage("google.com");
            HtmlForm form2 = page2.getFormByName("searchbook");

           
            form2.getSelectByName("ruteBerangkat").setSelectedAttribute("CGK", true);
            form2.getSelectByName("ruteTujuan").setSelectedAttribute("JOG", true);

            DateTime depart = new DateTime(2011, 12, 20, 0, 0, 0, 0);

            form2.getSelectByName("tglBerangkatPergi").setSelectedAttribute(depart.getDayOfMonth() + "-", true);
            form2.getSelectByName("blnBerangkatPergi").setSelectedAttribute(depart.getMonthOfYear() + "-", true);
            form2.getSelectByName("thnBerangkatPergi").setSelectedAttribute(depart.getYear() + "-", true);


            form2.getSelectByName("jmlPenumpang").setSelectedAttribute("2", true);
            form2.getSelectByName("jmlInfant").setSelectedAttribute("1", true);

            final HtmlSubmitInput btn = form2.getInputByName("Submit");
            final HtmlPage page3 = btn.click();


        } catch (Exception e) {
            System.out.println("" + e);

        }

        return null;


    }
}
